<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla controller library
jimport('joomla.application.component.controller');

/**
 * Hello World Component Controller
 */
class BookingControllerReservation extends JController
{
	function save()
	{
		JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_booking'.DS.'tables');
		$row =  JTable::getInstance('reservations', 'Table');
		if (!$row->bind( JRequest::get( 'post' ) )) {
			return JError::raiseWarning( 500, $row->getError() );
		}
		$id = 0;
		if($row->id != null) {
			$id = $row->id;
		}
		
		if($row->isBooking($id, $row->resource_id, $row->start_time, $row->end_time)){
			$row->id = -1;
			$row->ErrorMessage = "Time period is be booking";
			echo json_encode($row);
		}
		else if ($row->store()) {
			echo json_encode($row);
		}
		else
		{
			$row->id = -1;
			$row->ErrorMessage = "Save Booking Error";
		}
		echo json_encode($row);
		
	}
}
?>